﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Windows.Input;
using System.Windows.Controls;

using System.Configuration;
using System.IO;
using System.Threading;
using System.Text.RegularExpressions;


namespace DZ
{
    public class DataItem
    {
        private int key;
        private string name;
        public DataItem()
            : this(0, null)
        {
        }
        public DataItem(int key, string name)
        {
            this.key = key;
            this.name = name;
        }
        public int Key
        {
            get { return key; }
            set { key = value; }
        }
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public override string ToString()
        {
            return name;
        }
        public DataItem(DataItem dt)
        {
            this.key = dt.key;
            this.name = dt.name;
        }
    }
    class DZAswCommon
    {
        /// <summary>
        /// FUNCTION FOR DIAPLAYING WARNING MESSAGEBOX
        /// </summary>
        /// <param name="strMessage"></param>
        public void ShowWarning(String strMessage)
        {
            try
            {
                String strTitle = "LumiQuant i";
                MessageBox.Show(strMessage, strTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (Exception ex)
            {
                ClsCommon.ErrorLog(ex.ToString());
            }
        }
        /// <summary>
        /// FUNCTION FOR DISPLAYING SHOW MESSAGEBOX
        /// </summary>
        /// <param name="strMessage"></param>
        public void ShowMessage(String strMessage)
        {
            try
            {
                String strTitle = "Dezire Autostainer";
                MessageBox.Show(strMessage, strTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                ClsCommon.ErrorLog(ex.ToString());
                return;
            }
        }
        /// <summary>
        /// FUNCTION FOR DISPLAYING ERROR MESSAGEBOX
        /// </summary>
        /// <param name="strMessage"></param>
        public void ShowError(String strMessage)
        {
            try
            {
                String strTitle = "LumiQuant i";
                MessageBox.Show(strMessage, strTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                ClsCommon.ErrorLog(ex.ToString());
                return;
            }
        }
        /// <summary>
        /// RETURNS DIALOGRESULT CONTAING VALUES YES OR NO
        /// </summary>
        /// <param name="strMessage"></param>
        /// <returns></returns>
        public DialogResult ShowWarningYesNo(String strMessage)
        {
            try
            {
                String strTitle = "LumiQuant i";
                return (MessageBox.Show(strMessage, strTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning));
            }
            catch (Exception ex)
            {
                ClsCommon.ErrorLog(ex.ToString());
                return 0;
            }
        }
        
        public String GetComboboxText(ref System.Windows.Controls.ComboBox CmbToGetText)
        {
            try
            {
                int iSelection = CmbToGetText.SelectedIndex;
                if (iSelection != -1)
                {
                    String strSelection = CmbToGetText.SelectedItem.ToString();
                    return strSelection.Trim();
                }
                else
                {
                    return "";
                }
            }
            catch (Exception ex)
            {
                ClsCommon.ErrorLog(ex.ToString());
                return "";
            }
        }

        public int GetComboValueItem(ref System.Windows.Controls.ComboBox CmbToGetValue)
        {
            try
            {
                int valueToReturn = -1;
                if (CmbToGetValue.Items.Count == 0)
                    return valueToReturn;
                if (CmbToGetValue.SelectedIndex == -1)
                    return valueToReturn;
                DataItem sh = new DataItem((DataItem)CmbToGetValue.Items[CmbToGetValue.SelectedIndex]);
                valueToReturn = sh.Key;
                return valueToReturn;
            }
            catch (Exception ex)
            {
                ClsCommon.ErrorLog(ex.ToString());
                return 0;
            }
        }

        public void SetWPFGridProperty(ref System.Windows.Controls.DataGrid SetyOfGrid)
        {
            SetyOfGrid.IsReadOnly = true;
        }

        public int CheckEmptyTextBox(ref System.Windows.Controls.TextBox txtGetValue)
        {
            try
            {
                if (txtGetValue.Text == "")
                    return 0;
                else
                    return System.Convert.ToInt32(txtGetValue.Text);

            }
            catch (Exception ex)
            {
                ClsCommon.ErrorLog(ex.ToString());
                return 0;
            }
        }
        
        
           
        public static String FromatDecimal(Decimal dcmlNumber, short shtDecimal)////Returns TRUE if passed key is number or special keys or Decimal(oneTime)
        {
            try
            {
                switch (shtDecimal)
                {
                    case 1:
                        return dcmlNumber.ToString("0.0");
                    case 2:
                        return dcmlNumber.ToString("0.00");
                    case 3:
                        return dcmlNumber.ToString("0.000");
                    case 4:
                        return dcmlNumber.ToString("0.0000");

                    default:
                        return dcmlNumber.ToString("0.00");
                }
            }
            catch (Exception ex)
            {
                ClsCommon.ErrorLog(ex.ToString());
                return dcmlNumber.ToString("0.00");
            }
        }
        public static String FromatDecimal(float dcmlNumber, short shtDecimal)////Returns TRUE if passed key is number or special keys or Decimal(oneTime)
        {
            return FromatDecimal(System.Convert.ToDecimal(dcmlNumber), shtDecimal);
        }
        #region EVENT_HANDLER
        public delegate void ShortCut_MenuClicked(object Sender, System.Windows.Input.KeyEventArgs e);
        #endregion

    }
    public class CustomEventArgs : EventArgs
    {
        public CustomEventArgs(string s)
        {
            msg = s;
        }
        private string msg;
        public string Message
        {
            get { return msg; }
        }
    }
}
